int n, m, a = 0;
scanf("%d %d", &n, &m);
for (int i = 2; i <= n; i++) {
  a = (a + m) % i;
}
printf("%d", a + 1);